package top.rzhsky.util;

import java.io.*;
import java.util.List;

public class IOUtil {
    public static void export(File file, List<String> list) {
        try {
            BufferedWriter writer = new BufferedWriter(new FileWriter(file.getAbsolutePath()));
            for (String msg : list) {
                writer.write(msg);
                writer.newLine();
                writer.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static byte[] getBytes(File file) throws IOException {
        byte[] fileContext;FileInputStream inputStream = new FileInputStream(file);
        ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
        byte[] b = new byte[1024];

        int n;
        while ((n = inputStream.read(b)) != -1){
            bos.write(b,0,n);
        }
        inputStream.close();
        bos.close();

        fileContext = bos.toByteArray();
        return fileContext;
    }

    public static void getFile(byte[] data, File filePath) throws IOException {
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath));
        bos.write(data);
    }
}
